﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_ProjectInfo : System.Web.UI.Page
{
    public string strProjectMarker, strTitle, strContent;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                string ProjectId, strHospitalName = "";
               

                if (Request.QueryString["ProjectId"] != null)
                {
                    ProjectId = SysFun.IsSQL(Request.QueryString["ProjectId"].ToString());
                }
                else
                {
                    ProjectId = "1";
                }

                Db DbProject = new Db();

                string strSql = "Select projectid,ProjectMarker,Title,Content,ProjectHabitus,Hospitals,AccountId from Project where ProjectId=" + ProjectId.ToString();
                System.Data.IDataReader dr = DbProject.DataReader(strSql);
                if (dr.Read())
                {

                    strProjectMarker = dr["ProjectMarker"].ToString();
                    strTitle = dr["Title"].ToString();
                    strContent = dr["Content"].ToString();

                    txtProjectHabitus.Text = HZ.MBSM.BLL.ProjectHabitus.GetProjectHabitus((HZ.MBSM.BLL.enumProjectHabitus)(int.Parse(dr["ProjectHabitus"].ToString())));
                    strHospitalName = dr["Hospitals"].ToString();
                }
                dr.Close();
                dr.Dispose();
                strSql = "select accountid,hospitalname,area.areaname from hospital left join area on hospital.areaid=area.areaid where accountid  in (" + strHospitalName.Replace("'", "") + ")  order by area.areaname ";
                dr = DbProject.DataReader(strSql);
                //DataList1.DataSource = dr;
                //DataList1.DataBind();
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                int k = 1, j = 0;
                string AreaName="";
                sb.Append("<table width='98%' cellspacing='0' border='1' cellpadding='3'>");
                while (dr.Read())
                {
                    if (dr["hospitalname"].ToString() == "沙洋县人民医院")
                        k = k;
                    if (AreaName != SysFun.ToTrim(dr["AreaName"]))
                    {
                        AreaName = SysFun.ToTrim(dr["AreaName"]);
                        if (j != 0)
                        {

                            switch (k % 4)
                            {
                                case 0:
                                    sb.Append("</tr>");
                                    break;
                                case 3:
                                    sb.Append("<td>&nbsp;</td></tr>");
                                    break;
                                case 2:
                                    sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                                    break;
                                case 1:
                                    sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                                    break;

                            }
                        }
                        j = 1;                           
                        k=1;
                        sb.Append("<tr>");
                        sb.Append("<td colspan=3 style='color: #ff0033'>" + dr["AreaName"].ToString() + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                    }
                    else
                    {
                        if (k % 4 == 0)
                        {
                            j = 1;
                            k = 1;

                            sb.Append("</tr><tr>");
                        }
                    }
                    sb.Append("<td>" + dr["hospitalname"].ToString() + "</td>");

                    k++;
                    
                }
                switch (k % 4)
                {
                    case 0:
                        sb.Append("</tr>");
                        break;
                    case 3:
                        sb.Append("<td>&nbsp;</td></tr>");
                        break;
                    case 2:
                        sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                        break;
                    case 1:
                        sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                        break;

                }

                sb.Append("<table>");
                Label4.Text = sb.ToString();
                dr.Close();
                dr.Dispose();
                DbProject.Close();

            }
        }
    }

}
